<template>
	<!-- 瀑布流排版 -->
	<view class="" style="height: 100%;">
		<view class="waterfall">
			<uv-waterfall ref="waterfall" v-model="goodsList" :add-time="50" column-count="2" left-gap="10"
				right-gap="10" column-gap="8" column-width="40" @changeList="changeList">
				<template v-slot:list1>
					<view>
						<view v-for="(item, index) in list1" :key="index" class="waterfall-item">

							<view v-if="item.id" @click="todetail(item.id)" class="">
								<view class="waterfall-item__image">
									<image v-if="item.hasVideo" src="https://image.hzwltb69.com/app/imgs/chat/live.gif"
										class="lives" mode=""></image>
									<image :src="item.productImages" mode="widthFix"></image>
								</view>
								<view class="p-title">
									{{item.name}}
								</view>
								<view class="p-pirce">
									<view class="">
										<text style="font-size: 22rpx;margin-right: 2rpx;">￥</text>{{item.price}}
									</view>
									<view class="cat">抢购</view>
								</view>
								<view class="line" v-if="item.paySales != 0"></view>
								<view class="flagWord" v-if="item.paySales != 0">回头客{{item.paySales}}</view>
							</view>

							<view class="top-box" v-else>
								<view class="box-title">
									猜你喜欢
								</view>
								<view class="card-box">
									<view class="goods-crad" @click="todetail(likeData[0].productId)">
										<view class="img-box">
											<image :src="likeData[0].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[0].name}}
										</view>
									</view>
									<view class="goods-crad" @click="todetail(likeData[1].productId)">
										<view class="img-box">
											<image :src="likeData[1].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[1].name}}
										</view>
									</view>
								</view>
								<view class="card-box">
									<view class="goods-crad" @click="todetail(likeData[2].productId)">
										<view class="img-box">
											<image :src="likeData[2].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[2].name}}
										</view>
									</view>
									<view class="goods-crad" @click="todetail(likeData[3].productId)">
										<view class="img-box">
											<image :src="likeData[3].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[3].name}}
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</template>
				<template v-slot:list2>
					<view>
						<view v-for="(item, indexs) in list2" :key="indexs" class="waterfall-item">
							<view v-if="item.id" @click="todetail(item.id)" class="">
								<view class="waterfall-item__image">
									<image v-if="item.hasVideo" src="https://image.hzwltb69.com/app/imgs/chat/live.gif" class="lives" mode=""></image>
									<image :src="item.productImages" mode="widthFix"></image>
								</view>
								<view class="p-title">
									{{item.name}}
								</view>
								<view class="p-pirce">
									<view>
										<text style="font-size: 22rpx;margin-right: 2rpx;">￥</text>{{item.price}}
									</view>
									<view class="cat">抢购</view>
								</view>
							</view>
							<view class="top-box" v-else>
								<view class="box-title">
									猜你喜欢
								</view>
								<view class="card-box">
									<view class="goods-crad" @click="todetail(likeData[0].productId)">
										<view class="img-box">
											<image :src="likeData[0].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[0].name}}
										</view>
									</view>
									<view class="goods-crad" @click="todetail(likeData[1].productId)">
										<view class="img-box">
											<image :src="likeData[1].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[1].name}}
										</view>
									</view>
								</view>
								<view class="card-box">
									<view class="goods-crad" @click="todetail(likeData[2].productId)">
										<view class="img-box">
											<image :src="likeData[2].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[2].name}}
										</view>
									</view>
									<view class="goods-crad" @click="todetail(likeData[3].productId)">
										<view class="img-box">
											<image :src="likeData[3].thumbnail"></image>
										</view>
										<view class="goods-title">
											{{likeData[3].name}}
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</template>
			</uv-waterfall>
		</view>
	</view>
</template>

<script>
	export default {
		methods: {
			changeList(e) {
				this[e.name].push(e.value);
			},
			todetail(e) {
				this.$Router.push({
					path: '/pages/goods/detail',
					query: {
						id: e,
					}
				})
			},
			hasUserGet() {
				console.info(uni.getStorageSync("opents") == 1 ? 1 : 0)
				let that = this;
				that.$http('goods.recomlist', {
					current: that.page,
					pageSize: 10,
					opents: uni.getStorageSync("opents") == 1 ? 1 : 0
				}).then(res => {
					this.rebate = res.data.rebate
					if (that.goodsList.length == 0) {
						that.goodsList = res.data.product
						that.goodsList.splice(12, 0, {
							box: true
						})
					} else {
						that.goodsList = that.goodsList.concat(res.data.product)
					}
				});
			},
			getUserLike() {
				this.$http('goods.getBrowse')
					.then(res => {
						this.likeData = res.data
					})
			}
		},
		data() {
			return {
				goodsList: [],
				likeData: [],
				page: 1,
				list1: [], // 瀑布流第一列数据
				list2: [], // 瀑布流第二列数据
				rebate: 20, // 补贴
			}
		},
		created() {
			this.hasUserGet()
			this.getUserLike()
		},
	}
</script>

<style lang="scss" scoped>
	image {
		width: 350rpx !important;
	}

	.waterfall {
		background: #f6f6f6;
	}

	.waterfall-item {
		overflow: hidden;
		margin-top: 10px;
		border-radius: 6px;
	}

	.waterfall-item {
		background: #fff;

		.p-title {
			width: 350rpx;
			margin-top: 10rpx;
			padding: 0 10rpx;
			word-break: break-all;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;

			font-size: 28rpx;
			font-weight: 600;
			color: #030303;
		}

		.p-pirce {
			padding: 16rpx 10rpx 10rpx;
			display: flex;
			justify-content: space-between;
			color: #000;
			font-weight: 600;
			font-size: 32rpx;
			align-items: center;

			.cat {
				width: 86rpx;
				height: 46rpx;
				color: rgba(255, 255, 255, 1);
				background-color: rgba(238, 38, 50, 1);
				border-radius: 32rpx;
				font-size: 22rpx;
				line-height: 46rpx;
				text-align: center;
			}
		}

		.butie-box {
			padding: 10rpx;

			.butie {
				color: #db5235;
				height: 50rpx;
				line-height: 50rpx;
				font-size: 25rpx;
				display: inline-block;
				border: 1px solid #db5235;
				padding: 0 20rpx 0 20rpx;
				border-radius: 20rpx;
			}
		}
	}

	.waterfall-item__ft {
		padding: 20rpx;
		background: #fff;

		&__title {
			margin-bottom: 10rpx;
			line-height: 48rpx;
			font-weight: 700;

			.value {
				font-size: 32rpx;
				color: #303133;
			}
		}

		&__desc .value {
			font-size: 28rpx;
			color: #606266;
		}

		&__btn {
			padding: 10px 0;
		}
	}

	.lives {
		width: 40rpx !important;
		height: 40rpx !important;
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		z-index: 5;
	}

	.waterfall-item__image {
		position: relative;
	}

	.top-box {
		height: 450rpx;
		display: flex;
		flex-direction: column;

		.box-title {
			color: #EA9A00;
			font-style: italic;
			font-weight: bold;
			padding: 20rpx 0 0 20rpx;
		}

		.card-box {
			margin-top: 10rpx;
			height: 180rpx;
			width: 100%;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.goods-crad {
				flex: 1;
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.img-box {
					width: 150rpx !important;
					height: 150rpx !important;
					border-radius: 10rpx;
					overflow: hidden;
				}

				image {
					width: 100% !important;
					height: 100% !important;
				}

				.goods-title {
					width: 150rpx;
					font-size: 22rpx;
					text-align: center;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
		}
	}

	.line {
		width: 320rpx;
		height: 2rpx;
		color: rgba(80, 80, 80, 1);
		background-color: rgba(238, 237, 237, 1);
		margin: 10rpx auto;
	}

	.flagWord {
		color: rgba(188, 142, 93, 1);
		font-size: 24rpx;
		margin: 0 0 20rpx 16rpx;
	}
</style>